package eu.floranet.arquivo.temp;

import java.io.File;
import java.util.Properties;

import org.junit.Test;

import eu.floranet.arquivo.model.login.ArquivoLogin;
import eu.floranet.arquivo.model.login.ArquivoLoginException;
import eu.floranet.arquivo.model.permissions.ArquivoPermissions;
import eu.floranet.arquivo.model.persistence.PersistenceLinkManager;
import eu.floranet.arquivo.model.persistence.exception.EmptyLinkEntity;
import eu.floranet.arquivo.model.persistence.exception.EmptyLinkFile;
import eu.floranet.arquivo.model.persistence.exception.EmptyLinkProperties;
import eu.floranet.arquivo.model.persistence.exception.LinkException;
import eu.floranet.arquivo.model.persistence.link.PersistenceLinkEntityHandler;
import eu.floranet.arquivo.model.persistence.link.PersistenceLinkEntityManager;
import eu.floranet.arquivo.utils.Base64;
import eu.floranet.repositorio.sql.RelationUserGrupo;

public class Example02 {

	
	public void unitLogin(){
		ArquivoLogin login = new ArquivoLogin();
		
		System.out.println(login.getClass().getSimpleName());
		
		try {
			login.setLogin("ramos", "123456");
			ArquivoPermissions arqPermission = new ArquivoPermissions(login.getSysUsers());
			
		} catch (EclipseLinkException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ArquivoLoginException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for(RelationUserGrupo c : login.getSysUsers().getListaUserGrupo()){
			System.out.println(c.getUgGrupo().getGrupoNome());
		}
		
	}
	
	@Test
	public void unitPersistenceLinkManager(){
				
		Properties prop = new Properties();
		prop.put("eclipselink.logging.level", "FINE");
		prop.put("eclipselink.jdbc.driver", "com.mysql.jdbc.Driver");
		prop.put("eclipselink.jdbc.url", "jdbc:mysql://servidor:3306/ARQDIOCESE");
		prop.put("eclipselink.jdbc.user", "root");
		prop.put("eclipselink.jdbc.password", Base64.encodeObject("123456", Base64.GZIP | Base64.DONT_BREAK_LINES));
		
		PersistenceLinkManager plm = new PersistenceLinkManager();
		plm.getPersistenceLinkFile().setLinkFile(new File("database.xml"));
		plm.getPersistenceLinkProperties().setLinkProperties(prop);
		try {
			plm.readPersistenceProperties();
		} catch (EmptyLinkProperties e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (EmptyLinkFile e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (LinkException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		plm.addPersistenceLinkEntity(new PersistenceLinkEntityHandler(plm, "eArqDioceseModel"));
		
		try {
			PersistenceLinkEntityManager plem = new PersistenceLinkEntityManager();
			plem.initEntityManager();
		} catch (EmptyLinkEntity e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
